package com.gitee.openviducn.inspector.domain.vo.response.openvidu;

import com.alibaba.fastjson.JSON;
import com.gitee.openviducn.inspector.domain.vo.response.BaseResponse;
import com.google.common.collect.Lists;
import io.openvidu.java.client.OpenVidu;
import io.swagger.annotations.ApiModel;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: https://gitee.com/wesleyOne
 * @Date: 04.18 2020
 */
@ApiModel(value = "OpenVidu信息")
@Getter
@Setter
public class OpenViduVO extends BaseResponse {

    private static final long serialVersionUID = -5559887480084652346L;
    protected String hostname;
    protected List<SessionVO> activeSessions = Lists.newArrayList();

    public static OpenViduVO build(String hostname, OpenVidu openVidu) {
        OpenViduVO openViduVO = new OpenViduVO();
        openViduVO.setHostname(hostname);
        List<SessionVO> list = openVidu.getActiveSessions().stream().map(SessionVO::build).collect(Collectors.toList());
        openViduVO.setActiveSessions(list);
        return openViduVO;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
